package com.xindz.cn.mvptest.components.user.persenter;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.GetCallback;
import com.avos.avoscloud.LogInCallback;
import com.avos.avoscloud.SignUpCallback;
import com.xindz.cn.mvptest.base.BasePresenter;
import com.xindz.cn.mvptest.components.product.data.ProductBean;
import com.xindz.cn.mvptest.components.product.model.ProductModel;
import com.xindz.cn.mvptest.components.user.data.LZUser;
import com.xindz.cn.mvptest.components.user.model.LoginModel;
import com.xindz.cn.mvptest.components.user.model.RegisterModel;
import com.xindz.cn.mvptest.components.user.view.RegisterView;

/**
 * @name MvpTest
 * @class name：com.xindz.cn.mvptest.components.user.persenter
 * @describe describe
 * @anthor XINDZ
 * @time 2017/10/27 15:29
 * @change
 * @chang time
 * @class describe
 */
public class RegisterPersenter extends BasePresenter<RegisterView> {
    private RegisterModel registerModel;
    private LoginModel loginModel;
    private ProductModel productModel;

    public RegisterPersenter() {
        this.registerModel = new RegisterModel();
        this.loginModel = new LoginModel();
        this.productModel = new ProductModel();

    }

    public void register(String usernum, String pwd) {
        registerModel.register(usernum, pwd, new SignUpCallback() {
            @Override
            public void done(AVException e) {
                getView().toRegisterResult(e);
            }
        });
    }

    public void login(String usernum, String pwd) {
        loginModel.login(usernum, pwd, new LogInCallback<LZUser>() {
            @Override
            public void done(LZUser lzUser, AVException e) {
                if (e != null) {
                    getView().toLoginResult(lzUser, e);
                } else {
                    getView().toLoginResult(lzUser, null);
                }

            }
        });
    }

    public void getProduct(String ID) {
        productModel.getInBackground(ID, new GetCallback<ProductBean>() {

            @Override
            public void done(ProductBean productBean, AVException e) {
                getView().getProduct(productBean, e);
            }
        });
    }
}
